﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Prism.WebBuilder.Processors.Base;
using Prism.WebBuilder.Lib.Cui;

namespace Prism.WebBuilder.Processors
{
	public class Target : ProcessorBase, IObject
	{
		private List<IExecutableObject> _tasks;
		private string _name;

		public Target Init(string name)
		{
			_name = name;
			_tasks = new List<IExecutableObject>();
			RegisterObject(name, this);
			return this;
		}

		public Target Do(params object[] tasks)
		{
			foreach (object task in tasks)
			{
				if (task is IExecutableObject)
				{
					_tasks.Add(task as IExecutableObject);
				}
				else 
				{
					IExecutableObject obj = GetObject(task.ToString()) as IExecutableObject;
					if (obj != null)
						_tasks.Add(obj);
				}
			}
			return this;
		}

		public override void Process()
		{
			Cui.Info("making target {0}",_name);
			using (Cui.BeginIndent())
			{
				foreach (var o in _tasks)
					o.Execute();
			}
		}

		public void Trace(TracingOptions options)
		{
			
		}
	}
}
